package net.hn.hnms.biz.project.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import net.hn.hnms.biz.project.request.ComprehensiveQueryReq;
import net.hn.hnms.biz.project.vo.ComprehensiveQueryVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.poi.ss.formula.functions.T;

/**
 * @author 刘昊
 * @version 1.0.0
 * @ClassName ComprehensiveQueryMapper.java
 * @Description 综合查询
 * @date 2024-03-19 9:59
 */
@Mapper
public interface ComprehensiveQueryMapper extends BaseMapper<T> {

    @Select("<script>" +
            " SELECT " +
            " pi.project_id projectId,pi.project_code projectCode,pi.project_name projectName,pi.project_date projectDate, " +
            " pi.start_date startDate,pi.end_date endDate, " +
            " pb.budget_code budgetCode,pb.budget_title budgetTitle," +
            " ci.contract_code contractCode,ci.contract_title contractTitle," +
            " pi.total_amount totalAmount,pi.account_amount accountAmount,pi.construction_unit constructionUnit," +
            " pi.project_remark projectRemark" +
            " FROM " +
            " project_info pi " +
            " LEFT JOIN project_budget pb ON pi.project_id = pb.project_id " +
            " AND pb.del_flag = '0' " +
            " LEFT JOIN contract_info ci ON pi.project_id = ci.project_id " +
            " AND ci.del_flag = '0' " +
            " LEFT JOIN project_file pf ON pi.project_id = pf.project_id " +
            " AND pf.del_flag = '0' " +
            " where pi.del_flag = '0' " +
            " <if test='query.projectId!= null and query.projectId!= \"\" '>"+
            " and pi.project_id = #{query.projectId} " +
            " </if>"+
            " <if test='query.projectName!= null and query.projectName!= \"\" '>"+
            " and pi.project_name LIKE CONCAT('%', #{query.projectName}, '%')" +
            " </if>"+
            " <if test='query.constructionUnit!= null and query.constructionUnit!= \"\" '>"+
            " and pi.construction_unit LIKE CONCAT('%', #{query.constructionUnit}, '%')" +
            " </if>"+
            " <if test='query.mineCode!= null and query.mineCode!= \"\" '>"+
            " and pi.mine_code = #{query.mineCode} " +
            " </if>"+
            " <if test='query.contractTitle!= null and query.contractTitle!= \"\" '>"+
            " and ci.contract_title LIKE CONCAT('%', #{query.contractTitle}, '%') " +
            " </if>"+
            "<if test='query.projectDate!= null and query.projectDate!= \"\" '>" +
            " and pi.project_date = #{query.projectDate}::date " +
            " </if>" +
//            "<if test='query.startDate!= null and query.endDate!= \"\" '>" +
//            " and pi.start_date BETWEEN #{query.startDate} AND #{query.endDate}" +
//            " OR (pi.start_date <= #{query.endDate} AND pi.end_date >= #{query.startDate})" +
//            " </if>" +
            "</script>")
    Page<ComprehensiveQueryVo> queryPageList(Page<Object> build, @Param("query") ComprehensiveQueryReq req);
}
